﻿using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

namespace NTTDATA.BEENChina.ResultCertification.Util
{
   public  class Serializer<T>
    {

        public string SerializeXml(T t)
        {
            MemoryStream s = new MemoryStream();
            XmlSerializer formatter = new XmlSerializer(typeof(T));
            XmlSerializerNamespaces xmlSerializerNamespaces = new XmlSerializerNamespaces();
            xmlSerializerNamespaces.Add("", "");
            formatter.Serialize(s, t, xmlSerializerNamespaces);
            return Encoding.UTF8.GetString(s.ToArray());
        }
        public T DeSerializeXml(string data)
        {
            MemoryStream s = new MemoryStream(Encoding.UTF8.GetBytes(data));
            XmlSerializer formatter = new XmlSerializer(typeof(T));
            return (T)formatter.Deserialize(s);
        }
    }

   public class Serializer
   {
       public string SerializeXml(Type t, object o)
       {
           
           MemoryStream s = new MemoryStream();
          
           XmlSerializer formatter = new XmlSerializer(t);
           XmlSerializerNamespaces xmlSerializerNamespaces = new XmlSerializerNamespaces();
 
           xmlSerializerNamespaces.Add("", "");
           formatter.Serialize(s, o, xmlSerializerNamespaces);
           return   Encoding.UTF8.GetString(s.ToArray()); 
           


       

       }
       public object DeSerializeXml(Type t, string data)
       {
           MemoryStream s = new MemoryStream(Encoding.UTF8.GetBytes(data));
           XmlSerializer formatter = new XmlSerializer(t);
           return formatter.Deserialize(s);
            
       }
   }
}
